package com.navinfo.opentsp.platform.computing.analysis.entity.drivingAnalysis;


import com.navinfo.location.mileage.bean.Point;
import com.navinfo.opentsp.platform.location.protocol.common.OperationStatusAnalysisProto.OperationStatusAnalysis;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.bson.Document;

import java.util.ArrayList;
import java.util.List;

@Data
@NoArgsConstructor
public class StatisticsBean implements Cloneable{
    private long tid;
    private long times;
    private long startTS;
    private long endTS;
    private double oilConsumption;
    private int status;
    private List<Point> pointList;
    private int day;
    private int beginLat;
    private int beginLng;
    private int endLat;
    private int endLng;
    private double beginHeight;
    private double endHeight;
    private double mileage;
    private int offCount;
    private int onCount;
    private int count;

    public StatisticsBean(long tid, int day){
        this.tid = tid;
        this.day = day;
    }

    public void incrTimes(){
        this.times++;
    }

    public void incrOffCount(){
        this.offCount++;
    }

    public void incrOnCount(){
        this.onCount++;
    }

    public void incrCount(){
        this.count++;
    }

    public void addPoint(Point point){
        if(pointList == null){
            pointList = new ArrayList<>(8);
        }
        this.pointList.add(point);
    }

    public void clearData(){
        this.status = 0;
        this.startTS = 0;
        this.endTS = 0;
        if(this.pointList != null){
            this.pointList.clear();
        }
        this.pointList = null;
        this.oilConsumption = 0;
        this.times = 0;
        this.day = 0;
        this.tid = 0;
        this.beginLat = 0;
        this.beginLng = 0;
        this.endLat = 0;
        this.endLng = 0;
        this.beginHeight = 0;
        this.endHeight = 0;
        this.mileage = 0;
        this.onCount = 0;
        this.offCount = 0;
    }

    public Document toDocument(){
        Document document = new Document();
        document.put("tid", this.tid);
        document.put("times", this.times);
        document.put("startTS", this.startTS);
        document.put("endTS", this.endTS);
        document.put("oilConsumption", this.oilConsumption);
        document.put("status", this.status);
        document.put("day", this.day);
        document.put("beginLat", this.beginLat);
        document.put("beginLng", this.beginLng);
        document.put("endLat", this.endLat);
        document.put("endLng", this.endLng);
        document.put("beginHeight", this.beginHeight);
        document.put("endHeight", this.endHeight);
        document.put("mileage", this.mileage);
        return document;
    }

    public StatisticsBean copy(){
        StatisticsBean statisticsBean = new StatisticsBean();
        statisticsBean.setTid(tid);
        statisticsBean.setTimes(times);
        statisticsBean.setStartTS(startTS);
        statisticsBean.setEndTS(endTS);
        statisticsBean.setOilConsumption(oilConsumption);
        statisticsBean.setStatus(status);
        statisticsBean.setDay(day);
        statisticsBean.setBeginLat(beginLat);
        statisticsBean.setBeginLng(beginLng);
        statisticsBean.setBeginHeight(beginHeight);
        statisticsBean.setEndLat(endLat);
        statisticsBean.setEndLng(endLng);
        statisticsBean.setEndHeight(endHeight);
        statisticsBean.setMileage(mileage);
        return statisticsBean;
    }

    public OperationStatusAnalysis toProtobuf(){
        return OperationStatusAnalysis
                .newBuilder()
                .setTimes(times)
                .setStartTS(startTS)
                .setEndTS(endTS)
                .setOilConsumption(oilConsumption)
                .setStatus(status)
                .setDay(day)
                .setBeginLat(beginLat)
                .setBeginLng(beginLng)
                .setBeginHeight(beginHeight)
                .setEndLat(endLat)
                .setEndLng(endLng)
                .setEndHeight(endHeight)
                .setMileage(mileage)
                .build();
    }

}


